/*
** CPU Factory
*/

#include <string.h>
#include "smse2kincludes.h"
#include "CPUFactory.h"

static CCpuFactory* factories[256];
static int factorycount = 0;

void RegisterCPUFactory(CCpuFactory* factory) {
	

	// Catch unknown interface versions
	if (factory->GetInterfaceVersion() > CPU_INTERFACE_CURRENT_VERSION) {
		Msg("Couldn't register CPU factory for device %s: Invalid version %d, check source for problems\n",
					factory->GetName(), factory->GetInterfaceVersion());
		return;
	}

	factories[factorycount] = factory;
	factorycount ++;
}

ICpu* CPUFactory (const char* type) {
	for (int i=0;i<factorycount;i++) {
		if (!strcmpi(factories[i]->GetName(),type))
			return factories[i]->Init();
	}

	return NULL;
}

void OutputCPUList() {
	Msg("CPUs currently registered to CPUFactory:\n");
	for (int i=0;i<factorycount;i++) {
		Msg("%d. %s\n",i+1,factories[i]->GetName(),factories[i]->GetDescription());
	}
}